

import React, { useEffect } from 'react'
import flvjs from 'flv.js'
import dplayer from "dplayer"

import "./LiveRoomVideo.scss"

export default function LiveRoomVideo(props) {
    const roomInfo = props.state.roomInfo;
    useEffect(()=>{
        if(!roomInfo.flvAddr)return ;
        const dp = new dplayer({
            container: document.getElementById('videoContainer'),
            video: {
                url:  roomInfo.flvAddr,
                type: 'customFlv',
                customType: {
                    customFlv: function (video, player) {
                        const flvPlayer = flvjs.createPlayer({
                            type: 'flv',
                            url: roomInfo.flvAddr,
                        });
                        flvPlayer.attachMediaElement(video);
                        flvPlayer.load();
                    },
                },
            },
        });
    },[roomInfo]);
    return (
        <div className='LiveRoomVideo-container'>
            <div id="videoContainer"></div>
        </div>
    )
}
